
package br.com.aeternu.controleatendimento.atendimento.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.Date;
import java.util.ResourceBundle;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
import br.com.aeternu.controleatendimento.common.ui.EasyJDialog;
import com.toedter.calendar.JDateChooser;

public class UIFormAtendimento extends EasyJDialog
{

   private static final long serialVersionUID = 1L;
   /** Recursos de texto da classe */
   private static final ResourceBundle BUNDLE = ResourceBundle
            .getBundle("br.com.aeternu.controleatendimento.resources.gui.properties.UIFormAtendimento");
   private static final String BUNDLE_BOTAO_CONFIRMAR_ACTIONCOMMAND = "botao.confirmar.actioncommand";
   private static final String BUNDLE_BOTAO_CONFIRMAR_MNEMONICO = "botao.confirmar.mnemonico";
   private static final String BUNDLE_BOTAO_CONFIRMAR_TEXTO = "botao.confirmar.texto";
   private static final String BUNDLE_JANELA_TITULO = "janela.titulo";
   private static final String BUNDLE_ROTULO_CONCLUSAO_MNEMONICO = "rotulo.conclusao.mnemonico";
   private static final String BUNDLE_ROTULO_CONCLUSAO_TEXTO = "rotulo.conclusao.texto";
   private static final String BUNDLE_ROTULO_COORDENACAO_MNEMONICO = "rotulo.coordenacao.mnemonico";
   private static final String BUNDLE_ROTULO_COORDENACAO_TEXTO = "rotulo.coordenacao.texto";
   private static final String BUNDLE_ROTULO_DATA_MNEMONICO = "rotulo.data.mnemonico";
   private static final String BUNDLE_ROTULO_DATA_TEXTO = "rotulo.data.texto";
   private static final String BUNDLE_ROTULO_MEDICO_MNEMONICO = "rotulo.medico.mnemonico";
   private static final String BUNDLE_ROTULO_MEDICO_TEXTO = "rotulo.medico.texto";
   private static final String BUNDLE_ROTULO_PACIENTE_MNEMONICO = "rotulo.paciente.mnemonico";
   private static final String BUNDLE_ROTULO_PACIENTE_TEXTO = "rotulo.paciente.texto";
   private static final String BUNDLE_ROTULO_PARCEIRA_MNEMONICO = "rotulo.parceira.mnemonico";
   private static final String BUNDLE_ROTULO_PARCEIRA_TEXTO = "rotulo.parceira.texto";
   private static final String BUNDLE_ROTULO_PARTICULAR_MNEMONICO = "rotulo.particular.mnemonico";
   private static final String BUNDLE_ROTULO_PARTICULAR_TEXTO = "rotulo.particular.texto";
   private static final String BUNDLE_ROTULO_QTDE_MNEMONICO = "rotulo.quantidade.mnemonico";
   private static final String BUNDLE_ROTULO_QTDE_TEXTO = "rotulo.quantidade.texto";
   private static final String BUNDLE_ROTULO_TIPOEXAME_MNEMONICO = "rotulo.tipoexame.mnemonico";
   private static final String BUNDLE_ROTULO_TIPOEXAME_TEXTO = "rotulo.tipoexame.texto";
   private static final String BUNDLE_ROTULO_TURNO_MNEMONICO = "rotulo.turno.mnemonico";
   private static final String BUNDLE_ROTULO_TURNO_TEXTO = "rotulo.turno.texto";
   private JComboBox<String> conclusao;
   private final JPanel contentPanel = new JPanel();
   private JComboBox<String> coordenacao;
   private JDateChooser dataDoAtendimento;
   private JTextField dias;
   private JLabel lblConclusao;
   private JLabel lblCoordenacao;
   private JLabel lblDataDoAtendimento;
   private JLabel lblDiasHomologacao;
   private JLabel lblEmpresaParceira;
   private JLabel lblMedico;
   private JLabel lblPaciente;
   private JLabel lblParticular;
   private JLabel lblTipoDeExame;
   private JLabel lblTurno;
   private JComboBox<String> medico;
   private JTextField paciente;
   private JComboBox<String> parceira;
   private JComboBox<String> particular;
   private JComboBox<String> tipoExame;
   private JComboBox<String> turno;
   private IfcUIFormAtendimento listener;

   public UIFormAtendimento(IfcUIFormAtendimento listener)
   {
      super(BUNDLE.getString(BUNDLE_JANELA_TITULO));

      this.listener = listener;

      initComponents();
   }

   private void initComponents()
   {
      setBounds(100, 100, 450, 317);
      getContentPane().setLayout(new BorderLayout());
      contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
      getContentPane().add(contentPanel, BorderLayout.CENTER);
      GroupLayout gl_contentPanel = new GroupLayout(contentPanel);
      gl_contentPanel.setHorizontalGroup(
               gl_contentPanel.createParallelGroup(Alignment.LEADING)
                        .addGroup(
                           gl_contentPanel
                                    .createSequentialGroup()
                                    .addGroup(
                                       gl_contentPanel
                                                .createParallelGroup(Alignment.LEADING)
                                                .addGroup(
                                                   gl_contentPanel
                                                            .createSequentialGroup()
                                                            .addGroup(
                                                               gl_contentPanel
                                                                        .createParallelGroup(Alignment.TRAILING, false)
                                                                        .addComponent(getDataDoAtendimento(), Alignment.LEADING)
                                                                        .addComponent(getLblDataDoAtendimento(), Alignment.LEADING,
                                                                           GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                                                           Short.MAX_VALUE))
                                                            .addGap(18)
                                                            .addGroup(
                                                               gl_contentPanel
                                                                        .createParallelGroup(Alignment.LEADING, false)
                                                                        .addComponent(getTurno(), 0, GroupLayout.DEFAULT_SIZE,
                                                                           Short.MAX_VALUE)
                                                                        .addComponent(getLblTurno(), GroupLayout.DEFAULT_SIZE, 114,
                                                                           Short.MAX_VALUE))
                                                            .addGap(18)
                                                            .addGroup(
                                                               gl_contentPanel
                                                                        .createParallelGroup(Alignment.LEADING)
                                                                        .addComponent(getMedico(), 0, 178, Short.MAX_VALUE)
                                                                        .addComponent(getLblMedico(), GroupLayout.DEFAULT_SIZE, 178,
                                                                           Short.MAX_VALUE)))
                                                .addComponent(getLblPaciente(), GroupLayout.DEFAULT_SIZE, 414, Short.MAX_VALUE)
                                                .addComponent(getPaciente(), GroupLayout.DEFAULT_SIZE, 414, Short.MAX_VALUE)
                                                .addGroup(
                                                   gl_contentPanel
                                                            .createSequentialGroup()
                                                            .addGroup(
                                                               gl_contentPanel
                                                                        .createParallelGroup(Alignment.TRAILING, false)
                                                                        .addComponent(getConclusao(), Alignment.LEADING, 0,
                                                                           GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                                        .addComponent(getLblConclusao(), Alignment.LEADING,
                                                                           GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                                                           Short.MAX_VALUE)
                                                                        .addComponent(getParceira(), Alignment.LEADING, 0,
                                                                           GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                                        .addComponent(getLblEmpresaParceira(), Alignment.LEADING,
                                                                           GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                                                           Short.MAX_VALUE)
                                                                        .addComponent(getTipoExame(), Alignment.LEADING, 0,
                                                                           GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                                        .addComponent(getLblTipoDeExame(), Alignment.LEADING,
                                                                           GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE))
                                                            .addGap(18)
                                                            .addGroup(
                                                               gl_contentPanel
                                                                        .createParallelGroup(Alignment.LEADING)
                                                                        .addComponent(getDias(), GroupLayout.PREFERRED_SIZE,
                                                                           GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                                                        .addComponent(getLblDiasHomologacao())
                                                                        .addComponent(getCoordenacao(), 0, 221, Short.MAX_VALUE)
                                                                        .addComponent(getLblCoordenacao(), GroupLayout.DEFAULT_SIZE, 221,
                                                                           Short.MAX_VALUE)
                                                                        .addComponent(getLblParticular(), GroupLayout.DEFAULT_SIZE, 221,
                                                                           Short.MAX_VALUE)
                                                                        .addComponent(getParticular(), 0, 221, Short.MAX_VALUE))))
                                    .addContainerGap())
               );
      gl_contentPanel.setVerticalGroup(
               gl_contentPanel.createParallelGroup(Alignment.LEADING)
                        .addGroup(
                           gl_contentPanel
                                    .createSequentialGroup()
                                    .addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
                                             .addComponent(getLblDataDoAtendimento())
                                             .addComponent(getLblTurno())
                                             .addComponent(getLblMedico()))
                                    .addPreferredGap(ComponentPlacement.RELATED)
                                    .addGroup(
                                       gl_contentPanel
                                                .createParallelGroup(Alignment.BASELINE)
                                                .addComponent(getDataDoAtendimento(), GroupLayout.PREFERRED_SIZE, 21,
                                                   GroupLayout.PREFERRED_SIZE)
                                                .addComponent(getTurno(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                                   GroupLayout.PREFERRED_SIZE)
                                                .addComponent(getMedico(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                                   GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(ComponentPlacement.RELATED)
                                    .addComponent(getLblPaciente())
                                    .addPreferredGap(ComponentPlacement.RELATED)
                                    .addComponent(getPaciente(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                       GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(ComponentPlacement.RELATED)
                                    .addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
                                             .addComponent(getLblTipoDeExame())
                                             .addComponent(getLblCoordenacao()))
                                    .addPreferredGap(ComponentPlacement.RELATED)
                                    .addGroup(
                                       gl_contentPanel
                                                .createParallelGroup(Alignment.BASELINE)
                                                .addComponent(getTipoExame(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                                   GroupLayout.PREFERRED_SIZE)
                                                .addComponent(getCoordenacao(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                                   GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(ComponentPlacement.RELATED)
                                    .addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
                                             .addComponent(getLblEmpresaParceira())
                                             .addComponent(getLblParticular()))
                                    .addPreferredGap(ComponentPlacement.RELATED)
                                    .addGroup(
                                       gl_contentPanel
                                                .createParallelGroup(Alignment.BASELINE)
                                                .addComponent(getParceira(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                                   GroupLayout.PREFERRED_SIZE)
                                                .addComponent(getParticular(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                                   GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(ComponentPlacement.RELATED)
                                    .addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
                                             .addComponent(getLblConclusao())
                                             .addComponent(getLblDiasHomologacao()))
                                    .addPreferredGap(ComponentPlacement.RELATED)
                                    .addGroup(
                                       gl_contentPanel
                                                .createParallelGroup(Alignment.BASELINE)
                                                .addComponent(getConclusao(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                                   GroupLayout.PREFERRED_SIZE)
                                                .addComponent(getDias(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                                   GroupLayout.PREFERRED_SIZE))
                                    .addGap(0, 0, Short.MAX_VALUE))
               );
      contentPanel.setLayout(gl_contentPanel);
      {
         JPanel buttonPane = new JPanel();
         buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
         getContentPane().add(buttonPane, BorderLayout.SOUTH);
         {
            JButton confirmar = new JButton(BUNDLE.getString(BUNDLE_BOTAO_CONFIRMAR_TEXTO));
            confirmar.addActionListener(new ActionListener()
            {

               public void actionPerformed(ActionEvent e)
               {
                  confirmarActionPerformed();
               }
            });
            confirmar.setActionCommand(BUNDLE.getString(BUNDLE_BOTAO_CONFIRMAR_ACTIONCOMMAND));
            confirmar.setMnemonic(BUNDLE.getString(BUNDLE_BOTAO_CONFIRMAR_MNEMONICO).charAt(0));
            buttonPane.add(confirmar);
            getRootPane().setDefaultButton(confirmar);
         }
      }

      setVisible(true);
   }

   public JComboBox<String> getConclusao()
   {
      if (conclusao == null)
      {
         conclusao = new JComboBox<String>();
         conclusao.addItemListener(new ItemListener()
         {

            public void itemStateChanged(final ItemEvent e)
            {
               handleConclusaoItemStateChanged(e);
            }
         });
         conclusao.setEditable(true);
      }
      return conclusao;
   }

   public JComboBox<String> getCoordenacao()
   {
      if (coordenacao == null)
      {
         coordenacao = new JComboBox<String>();
         coordenacao.addItemListener(new ItemListener()
         {

            public void itemStateChanged(final ItemEvent e)
            {
               handleCoordenacaoItemStateChanged(e);
            }
         });
         coordenacao.setEditable(true);
      }
      return coordenacao;
   }

   public JDateChooser getDataDoAtendimento()
   {
      if (dataDoAtendimento == null)
      {
         dataDoAtendimento = new JDateChooser();
         dataDoAtendimento.setDate(new Date());
      }
      return dataDoAtendimento;
   }

   public JTextField getDias()
   {
      if (dias == null)
      {
         dias = new JTextField();
         dias.setColumns(3);
      }
      return dias;
   }

   public JLabel getLblConclusao()
   {
      if (lblConclusao == null)
      {
         lblConclusao = new JLabel(BUNDLE.getString(BUNDLE_ROTULO_CONCLUSAO_TEXTO));
         lblConclusao.setDisplayedMnemonic(BUNDLE.getString(BUNDLE_ROTULO_CONCLUSAO_MNEMONICO).charAt(0));
         lblConclusao.setLabelFor(getConclusao());
      }
      return lblConclusao;
   }

   public JLabel getLblCoordenacao()
   {
      if (lblCoordenacao == null)
      {
         lblCoordenacao = new JLabel(BUNDLE.getString(BUNDLE_ROTULO_COORDENACAO_TEXTO));
         lblCoordenacao.setDisplayedMnemonic(BUNDLE.getString(BUNDLE_ROTULO_COORDENACAO_MNEMONICO).charAt(0));
         lblCoordenacao.setLabelFor(getCoordenacao());
      }
      return lblCoordenacao;
   }

   public JLabel getLblDataDoAtendimento()
   {
      if (lblDataDoAtendimento == null)
      {
         lblDataDoAtendimento = new JLabel(BUNDLE.getString(BUNDLE_ROTULO_DATA_TEXTO));
         lblDataDoAtendimento.setDisplayedMnemonic(BUNDLE.getString(BUNDLE_ROTULO_DATA_MNEMONICO).charAt(0));
         lblDataDoAtendimento.setLabelFor(getDataDoAtendimento());
      }
      return lblDataDoAtendimento;
   }

   public JLabel getLblDiasHomologacao()
   {
      if (lblDiasHomologacao == null)
      {
         lblDiasHomologacao = new JLabel(BUNDLE.getString(BUNDLE_ROTULO_QTDE_TEXTO));
         lblDiasHomologacao.setDisplayedMnemonic(BUNDLE.getString(BUNDLE_ROTULO_QTDE_MNEMONICO).charAt(0));
         lblDiasHomologacao.setLabelFor(getDias());
      }
      return lblDiasHomologacao;
   }

   public JLabel getLblEmpresaParceira()
   {
      if (lblEmpresaParceira == null)
      {
         lblEmpresaParceira = new JLabel(BUNDLE.getString(BUNDLE_ROTULO_PARCEIRA_TEXTO));
         lblEmpresaParceira.setDisplayedMnemonic(BUNDLE.getString(BUNDLE_ROTULO_PARCEIRA_MNEMONICO).charAt(0));
         lblEmpresaParceira.setLabelFor(getParceira());
      }

      return lblEmpresaParceira;
   }

   public JLabel getLblMedico()
   {
      if (lblMedico == null)
      {
         lblMedico = new JLabel(BUNDLE.getString(BUNDLE_ROTULO_MEDICO_TEXTO));
         lblMedico.setDisplayedMnemonic(BUNDLE.getString(BUNDLE_ROTULO_MEDICO_MNEMONICO).charAt(0));
         lblMedico.setLabelFor(getMedico());
      }

      return lblMedico;
   }

   public JLabel getLblPaciente()
   {
      if (lblPaciente == null)
      {
         lblPaciente = new JLabel(BUNDLE.getString(BUNDLE_ROTULO_PACIENTE_TEXTO));
         lblPaciente.setDisplayedMnemonic(BUNDLE.getString(BUNDLE_ROTULO_PACIENTE_MNEMONICO).charAt(0));
         lblPaciente.setLabelFor(getPaciente());
      }

      return lblPaciente;
   }

   public JLabel getLblParticular()
   {
      if (lblParticular == null)
      {
         lblParticular = new JLabel(BUNDLE.getString(BUNDLE_ROTULO_PARTICULAR_TEXTO));
         lblParticular.setDisplayedMnemonic(BUNDLE.getString(BUNDLE_ROTULO_PARTICULAR_MNEMONICO).charAt(0));
         lblParticular.setLabelFor(getParticular());
      }
      return lblParticular;
   }

   public JLabel getLblTipoDeExame()
   {
      if (lblTipoDeExame == null)
      {
         lblTipoDeExame = new JLabel(BUNDLE.getString(BUNDLE_ROTULO_TIPOEXAME_TEXTO));
         lblTipoDeExame.setDisplayedMnemonic(BUNDLE.getString(BUNDLE_ROTULO_TIPOEXAME_MNEMONICO).charAt(0));
         lblTipoDeExame.setLabelFor(getTipoExame());
      }
      return lblTipoDeExame;
   }

   public JLabel getLblTurno()
   {
      if (lblTurno == null)
      {
         lblTurno = new JLabel(BUNDLE.getString(BUNDLE_ROTULO_TURNO_TEXTO));
         lblTurno.setDisplayedMnemonic(BUNDLE.getString(BUNDLE_ROTULO_TURNO_MNEMONICO).charAt(0));
         lblTurno.setLabelFor(getTurno());
      }
      return lblTurno;
   }

   public JComboBox<String> getMedico()
   {
      if (medico == null)
      {
         medico = new JComboBox<String>();
         medico.addItemListener(new ItemListener()
         {

            public void itemStateChanged(final ItemEvent e)
            {
               handleMedicoItemStateChanged(e);
            }
         });
         medico.setEditable(true);
         AutoCompleteDecorator.decorate(medico);
      }
      return medico;
   }

   public JTextField getPaciente()
   {
      if (paciente == null)
      {
         paciente = new JTextField();
         paciente.getDocument().addDocumentListener(new DocumentListener()
         {

            @Override
            public void insertUpdate(DocumentEvent e)
            {
               handlePacienteDocumentEvent(e);
            }

            @Override
            public void removeUpdate(DocumentEvent e)
            {
               handlePacienteDocumentEvent(e);
            }

            @Override
            public void changedUpdate(DocumentEvent e)
            {
               handlePacienteDocumentEvent(e);
            }
         });
         paciente.setColumns(10);
      }
      return paciente;
   }

   public JComboBox<String> getParceira()
   {
      if (parceira == null)
      {
         parceira = new JComboBox<String>();
         parceira.addItemListener(new ItemListener()
         {

            public void itemStateChanged(final ItemEvent e)
            {
               handleParceiraItemStateChanged(e);
            }
         });
         parceira.setEditable(true);
         AutoCompleteDecorator.decorate(parceira);
      }
      return parceira;
   }

   public JComboBox<String> getParticular()
   {
      if (particular == null)
      {
         particular = new JComboBox<String>();
         particular.addItemListener(new ItemListener()
         {

            public void itemStateChanged(final ItemEvent e)
            {
               handleParticularItemStateChanged(e);
            }
         });
         particular.setEditable(true);
         AutoCompleteDecorator.decorate(particular);
      }
      return particular;
   }

   public JComboBox<String> getTipoExame()
   {
      if (tipoExame == null)
      {
         tipoExame = new JComboBox<String>();
         tipoExame.addItemListener(new ItemListener()
         {

            public void itemStateChanged(final ItemEvent e)
            {
               handleTipoExameItemStateChanged(e);
            }
         });
         tipoExame.setEditable(true);
         AutoCompleteDecorator.decorate(tipoExame);
      }
      return tipoExame;
   }

   public JComboBox<String> getTurno()
   {
      if (turno == null)
      {
         turno = new JComboBox<String>();
         turno.addItemListener(new ItemListener()
         {

            public void itemStateChanged(final ItemEvent e)
            {
               handleTurnoItemStateChanged(e);
            }
         });
         turno.setEditable(true);
         AutoCompleteDecorator.decorate(turno);
      }

      return turno;
   }

   @Override
   public void sair()
   {
      dispose();
   }

   private void confirmarActionPerformed()
   {
      if (preenchimentoValido())
         listener.confirmar(this);
   }

   private boolean preenchimentoValido()
   {
      boolean ret = true;

      ret = validaDataDoAtendimento() & validaTurno() & validaMedico() & validaPaciente() & validaTipoExame() & validaCoordenacao()
         & validaParticular() & validaParceira() & validaConclusao();

      return ret;
   }

   private boolean validaConclusao()
   {
      boolean ret = true;

      if (((String) getConclusao().getSelectedItem()).isEmpty())
         ret = false;

      setMandatory(getLblConclusao(), !ret);

      return ret;
   }

   private boolean validaParceira()
   {
      boolean ret = true;

      if (((String) getCoordenacao().getSelectedItem()).isEmpty() && ((String) getParticular().getSelectedItem()).isEmpty()
         && ((String) getParceira().getSelectedItem()).isEmpty())
         ret = false;

      setMandatory(getLblEmpresaParceira(), !ret);

      return ret;
   }

   private boolean validaParticular()
   {
      boolean ret = true;

      if (((String) getCoordenacao().getSelectedItem()).isEmpty() && ((String) getParticular().getSelectedItem()).isEmpty()
         && ((String) getParceira().getSelectedItem()).isEmpty())
         ret = false;

      setMandatory(getLblParticular(), !ret);

      return ret;
   }

   private boolean validaCoordenacao()
   {
      boolean ret = true;

      if (((String) getCoordenacao().getSelectedItem()).isEmpty() && ((String) getParticular().getSelectedItem()).isEmpty()
         && ((String) getParceira().getSelectedItem()).isEmpty())
         ret = false;

      setMandatory(getLblCoordenacao(), !ret);

      return ret;
   }

   private boolean validaTipoExame()
   {
      boolean ret = true;

      if (((String) getTipoExame().getSelectedItem()).isEmpty())
         ret = false;

      setMandatory(getLblTipoDeExame(), !ret);

      return ret;
   }

   private boolean validaPaciente()
   {
      boolean ret = true;

      if (getPaciente().getText().isEmpty())
         ret = false;

      setMandatory(getLblPaciente(), !ret);

      return ret;
   }

   private boolean validaMedico()
   {
      boolean ret = true;

      if (((String) getMedico().getSelectedItem()).isEmpty())
         ret = false;

      setMandatory(getLblMedico(), !ret);

      return ret;
   }

   private boolean validaTurno()
   {
      boolean ret = true;

      if (((String) getTurno().getSelectedItem()).isEmpty())
         ret = false;

      setMandatory(getLblTurno(), !ret);

      return ret;
   }

   private boolean validaDataDoAtendimento()
   {
      boolean ret = true;

      if (getDataDoAtendimento().getDate() == null)
         ret = false;

      setMandatory(getLblDataDoAtendimento(), !ret);

      return ret;
   }

   private void setMandatory(JLabel label, boolean mandatory)
   {
      if (mandatory)
      {
         label.setForeground(Color.RED);
         label.setFont(label.getFont().deriveFont(Font.ITALIC));
      }
      else
      {
         label.setForeground(SystemColor.textText);
         label.setFont(label.getFont().deriveFont(Font.PLAIN));
      }
   }

   protected void handleTurnoItemStateChanged(final ItemEvent e)
   {
      if (e.getStateChange() == ItemEvent.SELECTED)
         setMandatory(getLblTurno(), !validaTurno());
   }

   protected void handleMedicoItemStateChanged(final ItemEvent e)
   {
      if (e.getStateChange() == ItemEvent.SELECTED)
         setMandatory(getLblMedico(), !validaMedico());
   }

   protected void handleTipoExameItemStateChanged(final ItemEvent e)
   {
      if (e.getStateChange() == ItemEvent.SELECTED)
         setMandatory(getLblTipoDeExame(), !validaTipoExame());
   }

   protected void handleCoordenacaoItemStateChanged(final ItemEvent e)
   {
      if (e.getStateChange() == ItemEvent.SELECTED)
      {
         boolean ret = validaCoordenacao();

         getParceira().setEnabled(!ret);
         getParticular().setEnabled(!ret);

         setMandatory(getLblCoordenacao(), !ret);
      }
   }

   protected void handleParceiraItemStateChanged(final ItemEvent e)
   {
      if (e.getStateChange() == ItemEvent.SELECTED)
      {
         boolean ret = validaParceira();

         getCoordenacao().setEnabled(!ret);
         getParticular().setEnabled(!ret);

         setMandatory(getLblEmpresaParceira(), !ret);
      }
   }

   protected void handleParticularItemStateChanged(final ItemEvent e)
   {
      if (e.getStateChange() == ItemEvent.SELECTED)
      {
         boolean ret = validaParticular();

         getParceira().setEnabled(!ret);
         getCoordenacao().setEnabled(!ret);

         setMandatory(getLblParticular(), !ret);
      }
   }

   protected void handleConclusaoItemStateChanged(final ItemEvent e)
   {
      if (e.getStateChange() == ItemEvent.SELECTED)
         setMandatory(getLblConclusao(), !validaConclusao());
   }

   protected void handlePacienteDocumentEvent(final DocumentEvent e)
   {
      setMandatory(getLblPaciente(), !validaPaciente());
   }
}
